package com.cema.manage.common.utils;

import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.models.auth.In;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResponseUtil {
    public static Object ok() {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 0);
        obj.put("errmsg", "成功");
        return obj;
    }

    public static Object ok(Object data) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 0);
        obj.put("errmsg", "成功");
        obj.put("data", data);
        return obj;
    }
    public static Object ok(Object data,boolean isUser) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", 0);
        obj.put("errmsg", "成功");
        obj.put("data", data);
        obj.put("isFlag", isUser);
        return obj;
    }


    public static Object okList(Page page) {
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("page", page.getCurrent());
        data.put("limit", page.getLimit());
        data.put("list", page.getRecords());
        data.put("total", page.getTotal());
        data.put("size", page.getRecords() == null ? 0 : page.getRecords().size());
        return ok(data);
    }

    public static Object okList(Integer pageNo, Integer pageSize, List page) {
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("page", pageNo);
        data.put("limit", pageSize);
        data.put("list", page);
        data.put("size", page.size());
        return ok(data);
    }
    public static Object okList(Integer pageNo, Integer pageSize, List page, Integer tatol) {
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("page", pageNo);
        data.put("limit", pageSize);
        data.put("list", page);
        data.put("size", page.size());
        data.put("total", tatol);
        return ok(data);
    }

    public static Object okList(List list, List pagedList) {
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("list", list);

        if (pagedList instanceof Page) {
            Page page = (Page) pagedList;
            data.put("total", page.getTotal());
            data.put("page", page.getCurrent());
            data.put("limit", page.getLimit());
            data.put("pages", page.getPages());
        } else {
            data.put("total", pagedList.size());
            data.put("page", 1);
            data.put("limit", pagedList.size());
            data.put("pages", 1);
        }

        return ok(data);
    }

    public static Object fail() {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", -1);
        obj.put("errmsg", "错误");
        return obj;
    }

    public static Object fail(int errno, String errmsg) {
        Map<String, Object> obj = new HashMap<String, Object>();
        obj.put("errno", errno);
        obj.put("errmsg", errmsg);
        return obj;
    }

    public static Object badArgument() {
        return fail(401, "参数不对");
    }

    public static Object badArgumentValue() {
        return fail(402, "参数值不对");
    }

    public static Object unlogin() {
        return fail(501, "请登录");
    }

    public static Object serious() {
        return fail(502, "系统内部错误");
    }

    public static Object unsupport() {
        return fail(503, "业务不支持");
    }

    public static Object updatedDateExpired() {
        return fail(504, "更新数据已经失效");
    }

    public static Object updatedDataFailed() {
        return fail(505, "更新数据失败");
    }

    public static Object unauthz() {
        return fail(506, "无操作权限");
    }
}
